package com.myxfd.superweibo.web;

import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * Created by Lulu on 2016/10/26.
 */

public class MyWebViewClient extends WebViewClient {
    private BrowserSupport mSupport;
    public MyWebViewClient(BrowserSupport support) {
        mSupport = support;
    }
    /**
     * 这个方法用于实现网址的拦截和特定动作的调用
     * 当这个方法返回false的时候, WebView会自己加载网址
     * 如果这个方法返回true, 那么WebView不会再进行网址的加载
     * @param view
     * @param url
     * @return
     */
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        boolean ret = false;
        if (url.startsWith("https://api.weibo.com/oauth2/default.html?code=")) {
            //TODO: 使用隐式意图 ACTION_VIEW, ACTION_CALL
            //调用回调接口, 传给外部程序
            if (mSupport != null) {
                mSupport.loadAppUrl(view, url);
            }
            ret = true;
        }
        return ret;
    }
}
